<?php
class database{
	private $connection;
	private $result;

	public function __construct($dbhost, $dbuser, $dbpass, $dbname){
		$this->connection = mysql_connect($dbhost, $dbuser, $dbpass);
		if($this->connection){
			$db = mysql_select_db($dbname);
			if(!$db){
				print "Error: DATABASE";
				exit;
			}
		}
		else{
			print "Error: DATABASE SERVER";
			exit;
		}
	}

	public function query($sql){
		if($this->result = mysql_query($sql, $this->connection)){
			return true;
		}
		else{
			return false;
		}
	}

	public function fetchRow($sql){
		$this->query($sql);
		$cnt = mysql_num_rows($this->result);
		if($cnt>0){
			while($row = mysql_fetch_row($this->result)) $ret[] = $row;
			return $ret;
		} else return null;
	}

	public function close(){
		mysql_close($this->connection);
	}
}
?>